/**
 * Created with IntelliJ IDEA.
 * User: duoba
 * Date: 16/2/24
 * Time: 上午9:28
 * To change this template use File | Settings | File Templates.
 */

package com.cake21.uitest.System.Core;

import java.util.ArrayDeque;
import java.util.HashMap;

public class Judge {
    /*计数器*/
    private Integer counter = 1;
    /*日志表*/
    private HashMap<String, HashMap<String, String>> logMap = new HashMap<String, HashMap<String, String>>();

    public HashMap<String, HashMap<String, String>> getLogMap() {
        return logMap;
    }

    /*日志队列*/
    private ArrayDeque<String> logDeque = new ArrayDeque<String>();

    public ArrayDeque<String> getLogDeque() {
        return logDeque;
    }

    /*判断 - 空/非空*/
    public void isNull(Object obj, String message) {
        is(obj == null, message);
    }

    public void isNull(Object obj, String message, String remark) {
        is(obj == null, message, remark);
    }

    public void notNull(Object obj, String message) {
        not(obj == null, message);
    }

    public void notNull(Object obj, String message, String remark) {
        not(obj == null, message, remark);
    }

    /*判断 - 相等/不相等*/
    public void isEqual(String str1, String str2, String message) {
        is(str1.equals(str2), message);
    }

    public void isEqual(String str1, String str2, String message, String remark) {
        is(str1.equals(str2), message, remark);
    }

    public void notEqual(String str1, String str2, String message) {
        not(str1.equals(str2), message);
    }

    public void notEqual(String str1, String str2, String message, String remark) {
        not(str1.equals(str2), message, remark);
    }

    public void isEqual(Integer int1, Integer int2, String message) {
        is(int1 == int2, message);
    }

    public void isEqual(Integer int1, Integer int2, String message, String remark) {
        is(int1 == int2, message, remark);
    }

    public void notEqual(Integer int1, Integer int2, String message) {
        is(int1 != int2, message);
    }

    public void notEqual(Integer int1, Integer int2, String message, String remark) {
        is(int1 != int2, message, remark);
    }

    /*支持方法*/
    public void is(Boolean bool, String message) {
        if (bool) {
            pass(message);
        } else {
            fail(message);
        }
    }

    public void is(Boolean bool, String message, String remark) {
        if (bool) {
            pass(message, remark);
        } else {
            fail(message, remark);
        }
    }

    public void not(Boolean bool, String message) {
        if (!bool) {
            pass(message);
        } else {
            fail(message);
        }
    }

    public void not(Boolean bool, String message, String remark) {
        if (!bool) {
            pass(message, remark);
        } else {
            fail(message, remark);
        }
    }

    public void pass(String message) {
        log("#89f080", message + " >> 测试通过");
    }

    public void pass(String message, String remark) {
        log("#89f080", message + " >> 测试通过", remark);
    }

    public void fail(String message) {
        log("#F0AFB4", message + " >> 测试不通过");
    }

    public void fail(String message, String remark) {
        log("#F0AFB4", message + " >> 测试不通过", remark);
    }

    public void notice(String message) {
        log("#f0ecd3", "警告: " + message);
    }

    public void notice(String message, String remark) {
        log("#f0ecd3", "警告: " + message, remark);
    }

    public void error(String message) {
        log("#deabab", "错误: " + message);
    }

    public void error(String message, String remark) {
        log("#deabab", "错误: " + message, remark);
    }

    public void info(String message) {
        log("#f6f6f6", message);
    }

    public void info(String message, String remark) {
        log("#f6f6f6", message, remark);
    }

    /*记录log*/
    public void log(String color, String message) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("color", color);
        map.put("message", message);
        map.put("remark", "");
        map.put("time", Server.currentTime());
        logMap.put(counter.toString(), map);
        logDeque.add(counter.toString());
        counter++;
    }

    /*记录log2*/
    public void log(String color, String message, String remark) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("color", color);
        map.put("message", message);
        map.put("remark", remark);
        map.put("time", Server.currentTime());
        logMap.put(counter.toString(), map);
        logDeque.add(counter.toString());
        counter++;
    }
}
